<template>
	<view class="pages-view">
		<view class="header-view">学校</view>
		<view style="padding: 30rpx;">
			<view class="list-view" v-for="(item,index) in list" :key="index" @click="handleJump(item)">
				<image class="list-image" :src="item.image" mode=""></image>
				<view class="list-text">
					{{item.title}}
				</view>
				<view class="list-time-view">
					{{item.update_time}}
				</view>
			</view>
			<u-empty v-if="list.length == 0" mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png" width="150px"
				height="150px" text="列表为空" textSize="18">
			</u-empty>
			<view style="padding-bottom: 100rpx;">
				<u-loadmore v-if="loading" status="loading" />
				<u-loadmore v-if="isLastPage" status="nomore" />
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				limit: 10,
				list: [],
				isLastPage: false,
				loading: false,
			}
		},
		onShow() {
			this.page = 1
			this.limit = 10
			this.list = []
			this.getShoolList()
		},
		// 刷新 上拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.isLastPage = false
			this.list = []
			this.getShoolList().finally(() => {
				// 停止当前页面下拉刷新
				uni.stopPullDownRefresh();
			});
		},
		// 加载下一页 下拉加载
		onReachBottom() {
			if (this.list.length >= this.page * this.limit) {
				this.isLastPage = false;
				this.page += 1;
				this.getShoolList();
			} else {
				this.isLastPage = true
			}
		},
		methods: {
			// 跳转
			handleJump(item){
				uni.navigateTo({
					url:'/pages/tab/school/school-info?id=' + item.id
				})
			},
			// 获取学校列表
			async getShoolList() {
				let res = await this.$api.post(global.apiUrls.postShoolList, {
					page: this.page,
					limit: this.limit,
					category_id: 27
				}, {
					token: true
				})
				let arr = []
				let image = ''
				arr = res.data.data.data.map(item=>{
					if(item.img_url.length>0){
						image = item.img_url[0]
					}else{
						image = ''
					}
					return {
						id:item.id,
						image:image,
						title:item.title,
						update_time:item.update_time
					}
				})
				this.list = [...this.list, ...arr]
			},
		}
	}
</script>

<style scoped>
	.list-time-view{
		font-weight: 500;
		font-size: 26rpx;
		color: #666666;
		text-align: right;
	}
	.list-text{
		font-weight: 400;
		font-size: 30rpx;
		color: #1A1A1A;
		margin-bottom: 20rpx;
	}
	.list-image{
		width: 100%;
		height: 300rpx;
		flex-shrink: 0;
		margin-bottom: 20rpx;
	}
	.list-view{
		padding: 30rpx;
		background-color: #ffffff;
		border-radius: 20rpx;
		margin-bottom: 20rpx;
	}
	.header-view{
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 20rpx;
		font-size: 16px;
		color: #333333;
		margin: 90rpx 0 30rpx 0;
	}
   .pages-view{
	   width: 100%;
	   min-height: 100vh;
	   overflow: hidden;
	   background: url('https://localelife.chunchuangkeji.cn/static/home_bg.jpg') no-repeat;
	   background-size:100% 100%;
   }
</style>
